package com.dating.view;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.dating.entities.Her;
import com.dating.entities.RowChat;

public class ChatAdapter extends BaseAdapter{
	Context mContext;
	Handler mHandler;
	Her mHer;
	
	ArrayList<RowChat> mArray;
	public ChatAdapter(Context context,Handler h,Her her,ArrayList<RowChat> array) {
		this.mContext=context;
		this.mArray=array;
		this.mHandler=h;
		this.mHer=her;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mArray.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return mArray.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		RowChatLayout v=(RowChatLayout)convertView;
		if(v==null){
			v=new RowChatLayout(mContext,mHer, mArray.get(position));
			v.setOnTaskListener(v);
			v.execute(mHandler);
		}
		if(mHer._bmp!=null){
			v.avatar.setImageBitmap(mHer._bmp);
		}
		return v;
	}

	public void setAvatar(Bitmap bmp) {
		mHer._bmp=bmp;
	}

}
